package org.jclosures;

import static org.jclosures.function.FunctionAssign.assign;

import java.util.HashSet;

import org.jclosures.collections.FunctionalCollection;
import org.jclosures.collections.impl.FunctionalCollectionDelegateDecorator;
import org.jclosures.function.Function1;
import org.jclosures.function.Function2;
import org.jclosures.function.base.AbstractFunction2;

public class PruebaClosures {

	public static void main(String[] args) {

		Integer f;

		Function1<Number, String> numToString = new Function1<Number, String>() {
			@Override
			public String apply(Number arg) {
				return arg.toString();
			}
		};

		Function1<Object, String> objToString = new Function1<Object, String>() {

			@Override
			public String apply(Object arg) {
				return "objToString: " + arg.toString();
			}
		};

		Function1<Integer, String> plus1 = new Function1<Integer, String>() {
			@Override
			public String apply(Integer arg) {
				return arg.toString();
			}
		};

		Function2<Integer, String, String> suma = new AbstractFunction2<Integer, String, String>() {
			@Override
			public String apply(Integer arg1, String arg2) {
				return arg1.toString() + "," + arg2;
			}
		};

		Function1<Object, Object> id = new Function1<Object, Object>() {
			@Override
			public Object apply(Object arg) {
				return arg;
			}
		};

		FunctionalCollection<Integer> c = new FunctionalCollectionDelegateDecorator<Integer>(
				new HashSet<Integer>());
		c.add(1);
		c.add(7);
		c.add(10);

		System.out.println(c.fold(suma, ""));
		System.out.println(suma.apply(43));

		// takeFunction(objToString)
		Function1<String, Object> param = null;
		takeFunction(assign(param, objToString));

		// numToString = objToString
		numToString = assign(numToString, objToString);
	}

	private static void takeFunction(Function1<String, Object> f) {
		System.out.println(f.apply("sasa"));
	}

}
